package com.zys.el.time.controller;

import com.zys.el.time.common.Result;
import com.zys.el.time.service.lambda_like.ILambdaLikeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/like")
@CrossOrigin
@Api(tags = "点赞接口")
public class LikeController {
    @Resource
    private ILambdaLikeService lambdaLikeService;

    @GetMapping("/thinking/change")
    @ApiOperation(value = "修改点赞状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "thinkingId", value = "帖子id", required = true),
            @ApiImplicitParam(name = "userId", value = "用户id", required = true),
            @ApiImplicitParam(name = "status", value = "点赞状态", required = true)
    })
    public Result changeThinkingLike(@RequestParam("thinkingId") String thinkingId,
                                     @RequestParam("userId") String userId,
                                     @RequestParam("status") Boolean status) {
        if (CheckUtil.isNotPass(thinkingId, userId) || status == null) return Result.fail("参数有误");
        lambdaLikeService.handleLike(Long.valueOf(thinkingId), Long.valueOf(userId), status);
//        thinkingLikeService.changeLikeStatus(thinkingId, userId, status);
        return Result.ok(status ? "点赞成功" : "取消点赞成功");
    }

}
